package Presentacion;

import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import Dominio.Cliente;

public class VerHorarios {

	private JFrame frame;

	public VerHorarios() {
		initialize();
		frame.setVisible(true);
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {		
		final Cliente c = new Cliente();
		final LinkedList<String[]> listaAsignaturas = c.consultarAsignatura(0);

		frame = new JFrame();
		frame.setBounds(100, 100, 486, 347);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		JPanel panel = new JPanel();
		frame.getContentPane().add(panel, BorderLayout.CENTER);
		GridBagLayout gbl_panel = new GridBagLayout();
		gbl_panel.columnWidths = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
		gbl_panel.rowHeights = new int[] { 0, 0, 0, 0, 0, 23, 23, 23, 23, 23, 23, 0 };
		gbl_panel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
		gbl_panel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
		panel.setLayout(gbl_panel);

		JLabel lblAsignaturas = new JLabel("Asignaturas: ");
		GridBagConstraints gbc_lblAsignaturas = new GridBagConstraints();
		gbc_lblAsignaturas.anchor = GridBagConstraints.EAST;
		gbc_lblAsignaturas.gridwidth = 4;
		gbc_lblAsignaturas.insets = new Insets(0, 0, 5, 5);
		gbc_lblAsignaturas.gridx = 2;
		gbc_lblAsignaturas.gridy = 2;
		panel.add(lblAsignaturas, gbc_lblAsignaturas);

		final JComboBox<String> comboBox = new JComboBox<String>();
		GridBagConstraints gbc_comboBox = new GridBagConstraints();
		
		gbc_comboBox.gridwidth = 5;
		gbc_comboBox.insets = new Insets(0, 0, 5, 5);
		gbc_comboBox.fill = GridBagConstraints.HORIZONTAL;
		gbc_comboBox.gridx = 6;
		gbc_comboBox.gridy = 2;
		panel.add(comboBox, gbc_comboBox);
		
		for (int i = 0; i < listaAsignaturas.size(); i++) {
			comboBox.addItem(listaAsignaturas.get(i)[0]);
		}

		GridBagConstraints gbc_btnMostrar = new GridBagConstraints();
		gbc_btnMostrar.gridwidth = 2;
		gbc_btnMostrar.insets = new Insets(0, 0, 5, 5);
		gbc_btnMostrar.gridx = 12;
		gbc_btnMostrar.gridy = 2;

		JLabel lblNombreDeLa = new JLabel("Asignatura:");
		GridBagConstraints gbc_lblNombreDeLa = new GridBagConstraints();
		gbc_lblNombreDeLa.anchor = GridBagConstraints.EAST;
		gbc_lblNombreDeLa.gridwidth = 4;
		gbc_lblNombreDeLa.insets = new Insets(0, 0, 5, 5);
		gbc_lblNombreDeLa.gridx = 1;
		gbc_lblNombreDeLa.gridy = 5;
		panel.add(lblNombreDeLa, gbc_lblNombreDeLa);

		final JLabel mostrarAsignatura = new JLabel("");
		GridBagConstraints gbc_mostrarAsignatura = new GridBagConstraints();
		gbc_mostrarAsignatura.anchor = GridBagConstraints.WEST;
		gbc_mostrarAsignatura.gridwidth = 9;
		gbc_mostrarAsignatura.insets = new Insets(0, 0, 5, 5);
		gbc_mostrarAsignatura.gridx = 5;
		gbc_mostrarAsignatura.gridy = 5;
		panel.add(mostrarAsignatura, gbc_mostrarAsignatura);

		JLabel lblLunes = new JLabel("Lunes: ");
		GridBagConstraints gbc_lblLunes = new GridBagConstraints();
		gbc_lblLunes.anchor = GridBagConstraints.EAST;
		gbc_lblLunes.gridwidth = 4;
		gbc_lblLunes.insets = new Insets(0, 0, 5, 5);
		gbc_lblLunes.gridx = 1;
		gbc_lblLunes.gridy = 6;
		panel.add(lblLunes, gbc_lblLunes);

		final JLabel mostrarLunes = new JLabel("");
		GridBagConstraints gbc_mostrarLunes = new GridBagConstraints();
		gbc_mostrarLunes.anchor = GridBagConstraints.WEST;
		gbc_mostrarLunes.gridwidth = 9;
		gbc_mostrarLunes.insets = new Insets(0, 0, 5, 5);
		gbc_mostrarLunes.gridx = 5;
		gbc_mostrarLunes.gridy = 6;
		panel.add(mostrarLunes, gbc_mostrarLunes);

		JButton btnMostrar = new JButton("Mostrar");
		panel.add(btnMostrar, gbc_btnMostrar);

		JLabel lblMartes = new JLabel("Martes: ");
		GridBagConstraints gbc_lblMartes = new GridBagConstraints();
		gbc_lblMartes.anchor = GridBagConstraints.EAST;
		gbc_lblMartes.gridwidth = 4;
		gbc_lblMartes.insets = new Insets(0, 0, 5, 5);
		gbc_lblMartes.gridx = 1;
		gbc_lblMartes.gridy = 7;
		panel.add(lblMartes, gbc_lblMartes);

		final JLabel mostrarMartes = new JLabel("");
		GridBagConstraints gbc_mostrarMartes = new GridBagConstraints();
		gbc_mostrarMartes.anchor = GridBagConstraints.WEST;
		gbc_mostrarMartes.gridwidth = 9;
		gbc_mostrarMartes.insets = new Insets(0, 0, 5, 5);
		gbc_mostrarMartes.gridx = 5;
		gbc_mostrarMartes.gridy = 7;
		panel.add(mostrarMartes, gbc_mostrarMartes);
		
		JLabel lblMiercoles = new JLabel("Miércoles: ");
		GridBagConstraints gbc_lblMiercoles = new GridBagConstraints();
		gbc_lblMiercoles.anchor = GridBagConstraints.EAST;
		gbc_lblMiercoles.gridwidth = 4;
		gbc_lblMiercoles.insets = new Insets(0, 0, 5, 5);
		gbc_lblMiercoles.gridx = 1;
		gbc_lblMiercoles.gridy = 8;
		panel.add(lblMiercoles, gbc_lblMiercoles);
		
		final JLabel mostrarMiercoles = new JLabel("");
		GridBagConstraints gbc_mostrarMiercoles = new GridBagConstraints();
		gbc_mostrarMiercoles.gridwidth = 9;
		gbc_mostrarMiercoles.anchor = GridBagConstraints.WEST;
		gbc_mostrarMiercoles.insets = new Insets(0, 0, 5, 5);
		gbc_mostrarMiercoles.gridx = 5;
		gbc_mostrarMiercoles.gridy = 8;
		panel.add(mostrarMiercoles, gbc_mostrarMiercoles);
		
		JLabel lblJueves = new JLabel("Jueves: ");
		GridBagConstraints gbc_lblJueves = new GridBagConstraints();
		gbc_lblJueves.anchor = GridBagConstraints.EAST;
		gbc_lblJueves.gridwidth = 4;
		gbc_lblJueves.insets = new Insets(0, 0, 5, 5);
		gbc_lblJueves.gridx = 1;
		gbc_lblJueves.gridy = 9;
		panel.add(lblJueves, gbc_lblJueves);
		
		final JLabel mostrarJueves = new JLabel("");
		GridBagConstraints gbc_mostrarJueves = new GridBagConstraints();
		gbc_mostrarJueves.anchor = GridBagConstraints.WEST;
		gbc_mostrarJueves.gridwidth = 9;
		gbc_mostrarJueves.insets = new Insets(0, 0, 5, 5);
		gbc_mostrarJueves.gridx = 5;
		gbc_mostrarJueves.gridy = 9;
		panel.add(mostrarJueves, gbc_mostrarJueves);
		
		JLabel lblViernes = new JLabel("Viernes: ");
		GridBagConstraints gbc_lblViernes = new GridBagConstraints();
		gbc_lblViernes.anchor = GridBagConstraints.EAST;
		gbc_lblViernes.gridwidth = 4;
		gbc_lblViernes.insets = new Insets(0, 0, 0, 5);
		gbc_lblViernes.gridx = 1;
		gbc_lblViernes.gridy = 10;
		panel.add(lblViernes, gbc_lblViernes);
		
		final JLabel mostrarViernes = new JLabel("");
		GridBagConstraints gbc_mostrarViernes = new GridBagConstraints();
		gbc_mostrarViernes.anchor = GridBagConstraints.WEST;
		gbc_mostrarViernes.gridwidth = 9;
		gbc_mostrarViernes.insets = new Insets(0, 0, 0, 5);
		gbc_mostrarViernes.gridx = 5;
		gbc_mostrarViernes.gridy = 10;
		panel.add(mostrarViernes, gbc_mostrarViernes);
		
		
		btnMostrar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String nombre = comboBox.getSelectedItem().toString();
				mostrarAsignatura.setText(nombre);
				LinkedList<String> horarios = c.consultarHorarios(nombre);
				mostrarLunes.setText(horarios.get(0));
				mostrarMartes.setText(horarios.get(1));
				mostrarMiercoles.setText(horarios.get(2));
				mostrarJueves.setText(horarios.get(3));
				mostrarViernes.setText(horarios.get(4));
			}
		});
	}
}
